/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.BehaviorStateMachines;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.model.xml.XMLUtility;

import edu.pku.sei.modeler.model.uml.Kernel.Constraint;
import edu.pku.sei.modeler.model.uml.Communications.Trigger;
import edu.pku.sei.modeler.model.uml.BasicBehaviors.Behavior;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.model.uml.Kernel.RedefinableElement;

import edu.pku.sei.modeler.model.uml.Kernel.NamedElement;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;

/**
 * @generated
 *
 */
public class Transition extends NamedElement implements ITransition {
	// attributes
	
	protected TransitionKind kind;
	
	
	
	protected boolean isLeaf;
	
	
	// references
	
	protected String guard = "";
	
	protected String trigger = "";
	
	protected String effect = "";
	
	
	protected MetaTypedList redefinedTransition;
	
	
	
	protected MetaTypedList redefinitionContext;
	
	protected MetaTypedList redefinedElement;
	
	// getters & setters for attributes
	private String combinedExpression = "";
	
	public String getCombinedExpression() {
		return combinedExpression;
	}
	
	public void refreshExpression() {
		combinedExpression = trigger;
		
		if(!guard.equals("")){
			combinedExpression = combinedExpression + " [ " + guard + " ] ";
		}
		
		if(!effect.equals("")){
			combinedExpression = combinedExpression + " / " + effect;
		}
		
	}
	
	public TransitionKind getKind() {
		return kind;
	}
	public void setKind(TransitionKind newKind) {
		TransitionKind oldkind = kind;
		kind = newKind;
		firePropertyChange(ModelPackage.TRANSITION_KIND, oldkind, newKind);
	}
	
	@MethodProperty(
			id = "TRANSITION_ISLEAF",
			catalog = "Model",
			name = ModelPackage.REDEFINABLEELEMENT_ISLEAF,
			setter = "setisLeaf"
			)
	
	public boolean getIsLeaf() {
		return isLeaf;
	}
	public void setIsLeaf(boolean newIsLeaf) {
		boolean oldisLeaf = isLeaf;
		isLeaf = newIsLeaf;
		firePropertyChange(ModelPackage.REDEFINABLEELEMENT_ISLEAF, oldisLeaf, newIsLeaf);
	}
	
	// getters for references
	@MethodProperty(id = "TRANSITION_GUARD", catalog = "Attribute", name = ModelPackage.TRANSITION_GUARD, setter = "setGuard")
	public String getGuard() {
		if(guard == null) {
			return "";
		}
		return guard;
	}
	public void setGuard(String newname) {
		String oldname = guard;
		guard = newname;
		firePropertyChange(ModelPackage.TRANSITION_GUARD, oldname, newname);
	}
	
	@MethodProperty(id = "TRANSITION_TRIGGER", catalog = "Attribute", name = ModelPackage.TRANSITION_TRIGGER, setter = "setTrigger")
	public String getTrigger() {
		if(trigger == null) {
			return "";
		}
		return trigger;
	}
	public void setTrigger(String newname) {
		String oldname = trigger;
		trigger = newname;
		firePropertyChange(ModelPackage.TRANSITION_TRIGGER, oldname, newname);
	}
	
	@MethodProperty(id = "TRANSITION_EFFECT", catalog = "Attribute", name = ModelPackage.TRANSITION_EFFECT, setter = "setEffect")
	public String getEffect() {
		if(effect == null) {
			return "";
		}
		return effect;
	}
	public void setEffect(String newname) {
		String oldname = effect;
		effect = newname;
		firePropertyChange(ModelPackage.TRANSITION_EFFECT, oldname, newname);
	}
	
	public MetaTypedList getRedefinedTransition() {
		if(redefinedTransition == null) {
			redefinedTransition = new MetaTypedList(Transition.class, this, ModelPackage.TRANSITION_REDEFINEDTRANSITION);
		}
		return redefinedTransition;
	}
	
	public MetaTypedList getRedefinitionContext() {
		if(redefinitionContext == null) {
			redefinitionContext = new MetaTypedList(Classifier.class, this, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT);
		}
		return redefinitionContext;
	}
	
	public MetaTypedList getRedefinedElement() {
		if(redefinedElement == null) {
			redefinedElement = new MetaTypedList(RedefinableElement.class, this, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT);
		}
		return redefinedElement;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeNode(root, ModelPackage.TRANSITION_KIND, kind);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.REDEFINABLEELEMENT_ISLEAF, isLeaf);
		
		// references
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.TRANSITION_GUARD, guard);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.TRANSITION_TRIGGER, trigger);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.TRANSITION_EFFECT, effect);
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.TRANSITION_REDEFINEDTRANSITION, redefinedTransition);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT, redefinitionContext);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT, redefinedElement);		
		
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		kind = (TransitionKind)XMLUtility.xmlInstance.deSerializeNode(root, ModelPackage.TRANSITION_KIND, this);
		
		isLeaf = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.REDEFINABLEELEMENT_ISLEAF);
		
		// references
		
		this.guard = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.TRANSITION_GUARD);
		
		this.trigger = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.TRANSITION_TRIGGER);
		
		this.effect = XMLUtility.xmlInstance.deSerializeString(root, ModelPackage.TRANSITION_EFFECT);
		
		this.getRedefinedTransition().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.TRANSITION_REDEFINEDTRANSITION, this));
		
		this.getRedefinitionContext().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT, this));
		
		this.getRedefinedElement().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT, this));
		
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		else if(ModelPackage.TRANSITION_KIND.equals(featureID)) {
			kind = (TransitionKind)value;
		}
		
		// references
		
		else if(ModelPackage.TRANSITION_REDEFINEDTRANSITION.equals(featureID)) {
			getRedefinedTransition().add(value);
		}
		
		else if(ModelPackage.REDEFINABLEELEMENT_REDEFINITIONCONTEXT.equals(featureID)) {
			getRedefinitionContext().add(value);
		}
		
		else if(ModelPackage.REDEFINABLEELEMENT_REDEFINEDELEMENT.equals(featureID)) {
			getRedefinedElement().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
	
}
 
 
 
 
 